package com.cookor.poi.modules.phy.service;

import com.cookor.poi.common.persistence.DataEntity;
import com.cookor.poi.common.persistence.Page;
import com.cookor.poi.common.service.CrudService;
import com.cookor.poi.common.utils.DateUtils;
import com.cookor.poi.modules.phy.dao.TSchedueTemplateDao;
import com.cookor.poi.modules.phy.dto.ScheduleExportDto;
import com.cookor.poi.modules.phy.dto.StockDto;
import com.cookor.poi.modules.phy.entity.TBookNo;
import com.cookor.poi.modules.phy.entity.TDoctor;
import com.cookor.poi.modules.phy.entity.TOrder;
import com.cookor.poi.modules.phy.entity.TSchedue;
import com.cookor.poi.modules.phy.entity.TSchedueTemplate;
import com.cookor.poi.modules.phy.entity.TShift;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
public class TSchedueTemplateService extends CrudService<TSchedueTemplateDao, TSchedueTemplate> {
  @Autowired
  private TSchedueService tSchedueService;
  
  @Autowired
  private TBookNoService tBookNoService;
  
  @Autowired
  private TShiftService tShiftService;
  
  @Autowired
  private TDoctorService tDoctorService;
  
  @Autowired
  private TOrderService tOrderService;
  
  public TSchedueTemplate get(String id) {
    return (TSchedueTemplate)super.get(id);
  }
  
  public List<TSchedueTemplate> findList(TSchedueTemplate tSchedueTemplate) {
    return super.findList( tSchedueTemplate);
  }
  
  public Page<TSchedueTemplate> findPage(Page<TSchedueTemplate> page, TSchedueTemplate tSchedueTemplate) {
    return super.findPage(page,  tSchedueTemplate);
  }
  
  @Transactional(readOnly = false, rollbackFor = {Exception.class})
  public void save(TSchedueTemplate tSchedueTemplate) {
    super.save( tSchedueTemplate);
  }
  
  @Transactional(readOnly = false, rollbackFor = {Exception.class})
  public void mySave(TSchedueTemplate tSchedueTemplate) throws Exception {
    ScheduleHandle(tSchedueTemplate);
    super.save( tSchedueTemplate);
  }
  
  @Transactional(readOnly = false)
  public void delete(TSchedueTemplate tSchedueTemplate) {
    super.delete( tSchedueTemplate);
  }
  
  @Transactional(readOnly = false, rollbackFor = {Exception.class})
  public void ScheduleHandle(TSchedueTemplate tSchedueTemplate) throws Exception {
    TShift tShift = new TShift();
    tShift.setTenantId(tSchedueTemplate.getTenantId());
    tShift.setShiftName(Integer.valueOf(TShift.am));
    List<TShift> list = this.tShiftService.findList(tShift);
    if (list.size() != 1)
      throw new Exception("该机构未设置上午班次！"); 
    String amBeginDate = ((TShift)list.get(0)).getBeginDate();
    String amEndDate = ((TShift)list.get(0)).getEndDate();
    tShift = new TShift();
    tShift.setTenantId(tSchedueTemplate.getTenantId());
    tShift.setShiftName(Integer.valueOf(TShift.pm));
    list = this.tShiftService.findList(tShift);
    if (list.size() != 1)
      throw new Exception("该机构未设置下午班次！"); 
    String pmBeginDate = ((TShift)list.get(0)).getBeginDate();
    String pmEndDate = ((TShift)list.get(0)).getEndDate();
    Integer year = Integer.valueOf(Integer.parseInt(DateUtils.getYear()));
    Integer month = Integer.valueOf(Integer.parseInt(DateUtils.getMonth()));
    TDoctor tDoctor = this.tDoctorService.get(tSchedueTemplate.getDoctorId().toString());
    TSchedue tSchedue = new TSchedue();
    tSchedue.setTenantId(tSchedueTemplate.getTenantId());
    tSchedue.setDoctorId(tSchedueTemplate.getDoctorId());
    tSchedue.setOfficeId(tDoctor.getOfficeId());
    tSchedue.setScheduleMonth(month);
    tSchedue.setScheduleYear(year);
    tSchedue.setTotal(Integer.valueOf(0));
    List<TBookNo> bookNoList = new ArrayList<>();
    Calendar c = Calendar.getInstance();
    c.add(2, 0);
    c.set(5, 1);
    int i = 1;
    while (c.get(2) != Integer.valueOf(month.intValue()).intValue() || (c.get(2) == 0 && Integer.valueOf(month.intValue()).intValue() == 12)) {
      Integer nowDay = Integer.valueOf(c.get(5));
      Integer nowWeek = Integer.valueOf(c.get(7));
      Integer weekStatus = getWeekStatus(nowWeek, tSchedueTemplate);
      tSchedue = getSchedue(tSchedueTemplate, nowDay, weekStatus, tSchedue);
      c.add(5, 1);
      if (weekStatus.intValue() == 4)
        continue; 
      if (weekStatus.intValue() != 2) {
        List<String> times = DateUtils.spliteDate(amBeginDate, amEndDate, tSchedueTemplate.getAm());
        i = 1;
        for (String time : times) {
          bookNoList.add(bookNoHandle(nowDay, month, year, tSchedueTemplate.getDoctorId(), tSchedueTemplate
                .getTenantId(), tDoctor.getOfficeId(), time, 1, i));
          i++;
        } 
      } 
      if (weekStatus.intValue() != 1) {
        List<String> times = DateUtils.spliteDate(pmBeginDate, pmEndDate, tSchedueTemplate.getPm());
        i = 1;
        for (String time : times) {
          bookNoList.add(bookNoHandle(nowDay, month, year, tSchedueTemplate.getDoctorId(), tSchedueTemplate
                .getTenantId(), tDoctor.getOfficeId(), time, 2, i));
          i++;
        } 
      } 
    } 
    TOrder queryOrder = new TOrder();
    queryOrder.setTenantId(tSchedueTemplate.getTenantId());
    queryOrder.setDoctorId(tSchedueTemplate.getDoctorId());
    if (!this.tOrderService.findList(queryOrder).isEmpty())
      return; 
    this.tSchedueService.trueDele(tSchedueTemplate.getTenantId(), tSchedueTemplate.getDoctorId(), year, month);
    this.tSchedueService.save(tSchedue);
    this.tBookNoService.deleteByParam(tSchedueTemplate.getTenantId(), null, tSchedueTemplate.getDoctorId(), year, month, null);
    if (!bookNoList.isEmpty())
      this.tBookNoService.batchInsert(bookNoList); 
    tSchedue = new TSchedue();
    if (month.intValue() == 12) {
      month = Integer.valueOf(1);
      year = Integer.valueOf(year.intValue() + 1);
    } else {
      month = Integer.valueOf(month.intValue() + 1);
    } 
    bookNoList = new ArrayList<>();
    tSchedue.setTenantId(tSchedueTemplate.getTenantId());
    tSchedue.setOfficeId(tDoctor.getOfficeId());
    tSchedue.setDoctorId(tSchedueTemplate.getDoctorId());
    tSchedue.setScheduleMonth(month);
    tSchedue.setScheduleYear(year);
    tSchedue.setTotal(Integer.valueOf(0));
    i = 1;
    while (c.get(2) != Integer.valueOf(month.intValue()).intValue() || (c.get(2) == 0 && Integer.valueOf(month.intValue()).intValue() == 12)) {
      Integer nowDay = Integer.valueOf(c.get(5));
      Integer nowWeek = Integer.valueOf(c.get(7));
      Integer weekStatus = getWeekStatus(nowWeek, tSchedueTemplate);
      tSchedue = getSchedue(tSchedueTemplate, nowDay, weekStatus, tSchedue);
      c.add(5, 1);
      if (weekStatus.intValue() == 4)
        continue; 
      if (weekStatus.intValue() != 2) {
        List<String> times = DateUtils.spliteDate(amBeginDate, amEndDate, tSchedueTemplate.getAm());
        i = 1;
        for (String time : times) {
          bookNoList.add(bookNoHandle(nowDay, month, year, tSchedueTemplate.getDoctorId(), tSchedueTemplate
                .getTenantId(), tDoctor.getOfficeId(), time, 1, i));
          i++;
        } 
      } 
      if (weekStatus.intValue() != 1) {
        List<String> times = DateUtils.spliteDate(pmBeginDate, pmEndDate, tSchedueTemplate.getPm());
        i = 1;
        for (String time : times) {
          bookNoList.add(bookNoHandle(nowDay, month, year, tSchedueTemplate.getDoctorId(), tSchedueTemplate
                .getTenantId(), tDoctor.getOfficeId(), time, 2, i));
          i++;
        } 
      } 
    } 
    this.tSchedueService.trueDele(tSchedueTemplate.getTenantId(), tSchedueTemplate.getDoctorId(), year, month);
    this.tSchedueService.save(tSchedue);
    this.tBookNoService.deleteByParam(tSchedueTemplate.getTenantId(), null, tSchedueTemplate.getDoctorId(), year, month, null);
    if (!bookNoList.isEmpty())
      this.tBookNoService.batchInsert(bookNoList); 
  }
  
  public static Integer getWeekStatus(Integer nowWeek, TSchedueTemplate tSchedueTemplate) {
    if (nowWeek.intValue() == 1)
      return tSchedueTemplate.getSun(); 
    if (nowWeek.intValue() == 2)
      return tSchedueTemplate.getMon(); 
    if (nowWeek.intValue() == 3)
      return tSchedueTemplate.getTue(); 
    if (nowWeek.intValue() == 4)
      return tSchedueTemplate.getWed(); 
    if (nowWeek.intValue() == 5)
      return tSchedueTemplate.getThu(); 
    if (nowWeek.intValue() == 6)
      return tSchedueTemplate.getFri(); 
    if (nowWeek.intValue() == 7)
      return tSchedueTemplate.getSat(); 
    return null;
  }
  
  public static TSchedue getSchedue(TSchedueTemplate template, Integer nowDay, Integer weekStatus, TSchedue tSchedue) {
    Integer am = template.getAm();
    Integer pm = template.getPm();
    if (nowDay.intValue() == 1) {
      tSchedue.setFirst(weekStatus);
      tSchedue.setAmFirst(am);
      tSchedue.setPmFirst(pm);
    } else if (nowDay.intValue() == 2) {
      tSchedue.setSecond(weekStatus);
      tSchedue.setAmSecond(am);
      tSchedue.setPmSecond(pm);
    } else if (nowDay.intValue() == 3) {
      tSchedue.setThird(weekStatus);
      tSchedue.setAmThird(am);
      tSchedue.setPmThird(pm);
    } else if (nowDay.intValue() == 4) {
      tSchedue.setFourth(weekStatus);
      tSchedue.setAmFourth(am);
      tSchedue.setPmFourth(pm);
    } else if (nowDay.intValue() == 5) {
      tSchedue.setFifth(weekStatus);
      tSchedue.setAmFifth(am);
      tSchedue.setPmFifth(pm);
    } else if (nowDay.intValue() == 6) {
      tSchedue.setSixth(weekStatus);
      tSchedue.setAmSixth(am);
      tSchedue.setPmSixth(pm);
    } else if (nowDay.intValue() == 7) {
      tSchedue.setSeventh(weekStatus);
      tSchedue.setAmSeventh(am);
      tSchedue.setPmSeventh(pm);
    } else if (nowDay.intValue() == 8) {
      tSchedue.setEighth(weekStatus);
      tSchedue.setAmEighth(am);
      tSchedue.setPmEighth(pm);
    } else if (nowDay.intValue() == 9) {
      tSchedue.setNinth(weekStatus);
      tSchedue.setAmNinth(am);
      tSchedue.setPmNinth(pm);
    } else if (nowDay.intValue() == 10) {
      tSchedue.setTenth(weekStatus);
      tSchedue.setAmTenth(am);
      tSchedue.setPmTenth(pm);
    } else if (nowDay.intValue() == 11) {
      tSchedue.setEleventh(weekStatus);
      tSchedue.setAmEleventh(am);
      tSchedue.setPmEleventh(pm);
    } else if (nowDay.intValue() == 12) {
      tSchedue.setTwelfth(weekStatus);
      tSchedue.setAmTwelfth(am);
      tSchedue.setPmTwelfth(pm);
    } else if (nowDay.intValue() == 13) {
      tSchedue.setThirteenth(weekStatus);
      tSchedue.setAmThirteenth(am);
      tSchedue.setPmThirteenth(pm);
    } else if (nowDay.intValue() == 14) {
      tSchedue.setFourteenth(weekStatus);
      tSchedue.setAmFourteenth(am);
      tSchedue.setPmFourteenth(pm);
    } else if (nowDay.intValue() == 15) {
      tSchedue.setFifteenth(weekStatus);
      tSchedue.setAmFifteenth(am);
      tSchedue.setPmFifteenth(pm);
    } else if (nowDay.intValue() == 16) {
      tSchedue.setSixteenth(weekStatus);
      tSchedue.setAmSixteenth(am);
      tSchedue.setPmSixteenth(pm);
    } else if (nowDay.intValue() == 17) {
      tSchedue.setSeventeenth(weekStatus);
      tSchedue.setAmSeventeenth(am);
      tSchedue.setPmSeventeenth(pm);
    } else if (nowDay.intValue() == 18) {
      tSchedue.setEighteenth(weekStatus);
      tSchedue.setAmEighteenth(am);
      tSchedue.setPmEighteenth(pm);
    } else if (nowDay.intValue() == 19) {
      tSchedue.setNineteenth(weekStatus);
      tSchedue.setAmNineteenth(am);
      tSchedue.setPmNineteenth(pm);
    } else if (nowDay.intValue() == 20) {
      tSchedue.setTwentieth(weekStatus);
      tSchedue.setAmTwentieth(am);
      tSchedue.setPmTwentieth(pm);
    } else if (nowDay.intValue() == 21) {
      tSchedue.setTwentyFirst(weekStatus);
      tSchedue.setAmTwentyFirst(am);
      tSchedue.setPmTwentyFirst(pm);
    } else if (nowDay.intValue() == 22) {
      tSchedue.setTwentySecond(weekStatus);
      tSchedue.setAmTwentySecond(am);
      tSchedue.setPmTwentySecond(pm);
    } else if (nowDay.intValue() == 23) {
      tSchedue.setTwentyThird(weekStatus);
      tSchedue.setAmTwentyThird(am);
      tSchedue.setPmTwentyThird(pm);
    } else if (nowDay.intValue() == 24) {
      tSchedue.setTwentyFourth(weekStatus);
      tSchedue.setAmTwentyFourth(am);
      tSchedue.setPmTwentyFourth(pm);
    } else if (nowDay.intValue() == 25) {
      tSchedue.setTwentyFifth(weekStatus);
      tSchedue.setAmTwentyFifth(am);
      tSchedue.setPmTwentyFifth(pm);
    } else if (nowDay.intValue() == 26) {
      tSchedue.setTwentySixth(weekStatus);
      tSchedue.setAmTwentySixth(am);
      tSchedue.setPmTwentySixth(pm);
    } else if (nowDay.intValue() == 27) {
      tSchedue.setTwentySeventh(weekStatus);
      tSchedue.setAmTwentySeventh(am);
      tSchedue.setPmTwentySeventh(pm);
    } else if (nowDay.intValue() == 28) {
      tSchedue.setTwentyEighth(weekStatus);
      tSchedue.setAmTwentyEighth(am);
      tSchedue.setPmTwentyEighth(pm);
    } else if (nowDay.intValue() == 29) {
      tSchedue.setTwentyNinth(weekStatus);
      tSchedue.setAmTwentyNinth(am);
      tSchedue.setPmTwentyNinth(pm);
    } else if (nowDay.intValue() == 30) {
      tSchedue.setThirtieth(weekStatus);
      tSchedue.setAmThirtieth(am);
      tSchedue.setPmThirtieth(pm);
    } else if (nowDay.intValue() == 31) {
      tSchedue.setThirtyFirst(weekStatus);
      tSchedue.setAmThirtyFirst(am);
      tSchedue.setPmThirtyFirst(pm);
    } 
    return tSchedue;
  }
  
  public static ScheduleExportDto getSchedueForExport(ScheduleExportDto dto, Integer nowDay, TSchedue tSchedue) {
    dto = new ScheduleExportDto();
    if (nowDay.intValue() == 1) {
      dto.setWeekStatus(tSchedue.getFirst());
      dto.setAmStock(tSchedue.getAmFirst());
      dto.setPmStock(tSchedue.getPmFirst());
    } else if (nowDay.intValue() == 2) {
      dto.setWeekStatus(tSchedue.getSecond());
      dto.setAmStock(tSchedue.getAmSecond());
      dto.setPmStock(tSchedue.getPmSecond());
    } else if (nowDay.intValue() == 3) {
      dto.setWeekStatus(tSchedue.getThird());
      dto.setAmStock(tSchedue.getAmThird());
      dto.setPmStock(tSchedue.getPmThird());
    } else if (nowDay.intValue() == 4) {
      dto.setWeekStatus(tSchedue.getFourth());
      dto.setAmStock(tSchedue.getAmFourth());
      dto.setPmStock(tSchedue.getPmFourth());
    } else if (nowDay.intValue() == 5) {
      dto.setWeekStatus(tSchedue.getFifth());
      dto.setAmStock(tSchedue.getAmFifth());
      dto.setPmStock(tSchedue.getPmFifth());
    } else if (nowDay.intValue() == 6) {
      dto.setWeekStatus(tSchedue.getSixth());
      dto.setAmStock(tSchedue.getAmSixth());
      dto.setPmStock(tSchedue.getPmSixth());
    } else if (nowDay.intValue() == 7) {
      dto.setWeekStatus(tSchedue.getSeventh());
      dto.setAmStock(tSchedue.getAmSeventh());
      dto.setPmStock(tSchedue.getPmSeventh());
    } else if (nowDay.intValue() == 8) {
      dto.setWeekStatus(tSchedue.getEighth());
      dto.setAmStock(tSchedue.getAmEighth());
      dto.setPmStock(tSchedue.getPmEighth());
    } else if (nowDay.intValue() == 9) {
      dto.setWeekStatus(tSchedue.getNinth());
      dto.setAmStock(tSchedue.getAmNinth());
      dto.setPmStock(tSchedue.getPmNinth());
    } else if (nowDay.intValue() == 10) {
      dto.setWeekStatus(tSchedue.getTenth());
      dto.setAmStock(tSchedue.getAmTenth());
      dto.setPmStock(tSchedue.getPmTenth());
    } else if (nowDay.intValue() == 11) {
      dto.setWeekStatus(tSchedue.getEighteenth());
      dto.setAmStock(tSchedue.getAmEleventh());
      dto.setPmStock(tSchedue.getPmEleventh());
    } else if (nowDay.intValue() == 12) {
      dto.setWeekStatus(tSchedue.getTwelfth());
      dto.setAmStock(tSchedue.getAmTwelfth());
      dto.setPmStock(tSchedue.getPmTwelfth());
    } else if (nowDay.intValue() == 13) {
      dto.setWeekStatus(tSchedue.getThirteenth());
      dto.setAmStock(tSchedue.getAmThirteenth());
      dto.setPmStock(tSchedue.getPmThirteenth());
    } else if (nowDay.intValue() == 14) {
      dto.setWeekStatus(tSchedue.getFourteenth());
      dto.setAmStock(tSchedue.getAmFourteenth());
      dto.setPmStock(tSchedue.getPmFourteenth());
    } else if (nowDay.intValue() == 15) {
      dto.setWeekStatus(tSchedue.getFifteenth());
      dto.setAmStock(tSchedue.getAmFifteenth());
      dto.setPmStock(tSchedue.getPmFifteenth());
    } else if (nowDay.intValue() == 16) {
      dto.setWeekStatus(tSchedue.getSixteenth());
      dto.setAmStock(tSchedue.getAmSixteenth());
      dto.setPmStock(tSchedue.getPmSixteenth());
    } else if (nowDay.intValue() == 17) {
      dto.setWeekStatus(tSchedue.getSeventeenth());
      dto.setAmStock(tSchedue.getAmSeventeenth());
      dto.setPmStock(tSchedue.getPmSeventeenth());
    } else if (nowDay.intValue() == 18) {
      dto.setWeekStatus(tSchedue.getEighteenth());
      dto.setAmStock(tSchedue.getAmEighteenth());
      dto.setPmStock(tSchedue.getPmEighteenth());
    } else if (nowDay.intValue() == 19) {
      dto.setWeekStatus(tSchedue.getNineteenth());
      dto.setAmStock(tSchedue.getAmNineteenth());
      dto.setPmStock(tSchedue.getPmNineteenth());
    } else if (nowDay.intValue() == 20) {
      dto.setWeekStatus(tSchedue.getTwentieth());
      dto.setAmStock(tSchedue.getAmTwentieth());
      dto.setPmStock(tSchedue.getPmTwentieth());
    } else if (nowDay.intValue() == 21) {
      dto.setWeekStatus(tSchedue.getTwentyFirst());
      dto.setAmStock(tSchedue.getAmTwentyFirst());
      dto.setPmStock(tSchedue.getPmTwentyFirst());
    } else if (nowDay.intValue() == 22) {
      dto.setWeekStatus(tSchedue.getTwentySecond());
      dto.setAmStock(tSchedue.getAmTwentySecond());
      dto.setPmStock(tSchedue.getPmTwentySecond());
    } else if (nowDay.intValue() == 23) {
      dto.setWeekStatus(tSchedue.getTwentyThird());
      dto.setAmStock(tSchedue.getAmTwentyThird());
      dto.setPmStock(tSchedue.getPmTwentyThird());
    } else if (nowDay.intValue() == 24) {
      dto.setWeekStatus(tSchedue.getTwentyFourth());
      dto.setAmStock(tSchedue.getAmTwentyFourth());
      dto.setPmStock(tSchedue.getPmTwentyFourth());
    } else if (nowDay.intValue() == 25) {
      dto.setWeekStatus(tSchedue.getTwentyFifth());
      dto.setAmStock(tSchedue.getAmTwentyFifth());
      dto.setPmStock(tSchedue.getPmTwentyFifth());
    } else if (nowDay.intValue() == 26) {
      dto.setWeekStatus(tSchedue.getTwentySixth());
      dto.setAmStock(tSchedue.getTwentySixth());
      dto.setPmStock(tSchedue.getPmTwentySixth());
    } else if (nowDay.intValue() == 27) {
      dto.setWeekStatus(tSchedue.getTwentySeventh());
      dto.setAmStock(tSchedue.getAmTwentySeventh());
      dto.setPmStock(tSchedue.getPmTwentySeventh());
    } else if (nowDay.intValue() == 28) {
      dto.setWeekStatus(tSchedue.getTwentyEighth());
      dto.setAmStock(tSchedue.getAmTwentyEighth());
      dto.setPmStock(tSchedue.getPmTwentyEighth());
    } else if (nowDay.intValue() == 29) {
      dto.setWeekStatus(tSchedue.getTwentyNinth());
      dto.setAmStock(tSchedue.getAmTwentyNinth());
      dto.setPmStock(tSchedue.getPmTwentyNinth());
    } else if (nowDay.intValue() == 30) {
      dto.setWeekStatus(tSchedue.getThirtieth());
      dto.setAmStock(tSchedue.getAmThirtieth());
      dto.setPmStock(tSchedue.getPmThirtieth());
    } else if (nowDay.intValue() == 31) {
      dto.setWeekStatus(tSchedue.getThirtyFirst());
      dto.setAmStock(tSchedue.getAmThirtyFirst());
      dto.setPmStock(tSchedue.getPmThirtyFirst());
    } else {
      return null;
    } 
    return dto;
  }
  
  public List<String> DateHandler(String begin, String end, Integer num) throws Exception {
    long beginDate = DateUtils.parseDate(begin, new String[] { "HH:mm:ss" }).getTime();
    long endDate = DateUtils.parseDate(end, new String[] { "HH:mm:ss" }).getTime();
    if (endDate <= beginDate)
      throw new Exception("时间参数有误"); 
    Long distance = Long.valueOf((endDate - beginDate) / 1000L);
    if (distance.longValue() <= 10L)
      throw new Exception("班次间隔设置太短了"); 
    distance = Long.valueOf(distance.longValue() / num.intValue());
    List<String> list = new ArrayList<>();
    while (beginDate <= endDate) {
      list.add(DateUtils.formatDate(new Date(beginDate), new Object[] { "HH:mm:ss" }));
      Calendar calendar = Calendar.getInstance();
      calendar.setTime(new Date(beginDate));
      calendar.add(13, distance.intValue());
      if (calendar.getTime().getTime() > endDate) {
        if (beginDate != endDate)
          list.add(DateUtils.formatDate(new Date(endDate), new Object[] { "HH:mm:ss" })); 
        beginDate = calendar.getTime().getTime();
        continue;
      } 
      beginDate = calendar.getTime().getTime();
    } 
    return list;
  }
  
  public static TBookNo bookNoHandle(Integer nowDay, Integer month, Integer year, Integer doctorId, Integer tenantId, Integer officeId, String time, int type, int no) {
    TBookNo bookNo = new TBookNo();
    bookNo.setBookDay(nowDay);
    bookNo.setBookMonth(month);
    bookNo.setBookYear(year);
    bookNo.setDoctorId(doctorId);
    bookNo.setOfficeId(officeId);
    bookNo.setTenantId(tenantId);
    bookNo.setBookTime(time);
    bookNo.setType(Integer.valueOf(type));
    bookNo.setBookNo(Integer.valueOf(no));
    bookNo.preInsert();
    return bookNo;
  }
  
  public static StockDto getStock(TSchedue tSchedue, Integer nowDay) {
    StockDto stockDto = new StockDto();
    if (nowDay.intValue() == 1) {
      stockDto.setAmStock(tSchedue.getAmFirst());
      stockDto.setPmStock(tSchedue.getPmFirst());
      return stockDto;
    } 
    if (nowDay.intValue() == 2) {
      stockDto.setAmStock(tSchedue.getAmSecond());
      stockDto.setPmStock(tSchedue.getPmSecond());
      return stockDto;
    } 
    if (nowDay.intValue() == 3) {
      stockDto.setAmStock(tSchedue.getAmThird());
      stockDto.setPmStock(tSchedue.getPmThird());
      return stockDto;
    } 
    if (nowDay.intValue() == 4) {
      stockDto.setAmStock(tSchedue.getAmFourth());
      stockDto.setPmStock(tSchedue.getPmFourth());
      return stockDto;
    } 
    if (nowDay.intValue() == 5) {
      stockDto.setAmStock(tSchedue.getAmFifth());
      stockDto.setPmStock(tSchedue.getPmFifth());
      return stockDto;
    } 
    if (nowDay.intValue() == 6) {
      stockDto.setAmStock(tSchedue.getAmSixth());
      stockDto.setPmStock(tSchedue.getPmSixth());
      return stockDto;
    } 
    if (nowDay.intValue() == 7) {
      stockDto.setAmStock(tSchedue.getAmSeventh());
      stockDto.setPmStock(tSchedue.getPmSeventh());
      return stockDto;
    } 
    if (nowDay.intValue() == 8) {
      stockDto.setAmStock(tSchedue.getAmEighth());
      stockDto.setPmStock(tSchedue.getPmEighth());
      return stockDto;
    } 
    if (nowDay.intValue() == 9) {
      stockDto.setAmStock(tSchedue.getAmNinth());
      stockDto.setPmStock(tSchedue.getPmNinth());
      return stockDto;
    } 
    if (nowDay.intValue() == 10) {
      stockDto.setAmStock(tSchedue.getAmTenth());
      stockDto.setPmStock(tSchedue.getPmTenth());
      return stockDto;
    } 
    if (nowDay.intValue() == 11) {
      stockDto.setAmStock(tSchedue.getAmEleventh());
      stockDto.setPmStock(tSchedue.getPmEleventh());
      return stockDto;
    } 
    if (nowDay.intValue() == 12) {
      stockDto.setAmStock(tSchedue.getAmTwelfth());
      stockDto.setPmStock(tSchedue.getPmTwelfth());
      return stockDto;
    } 
    if (nowDay.intValue() == 13) {
      stockDto.setAmStock(tSchedue.getAmThirteenth());
      stockDto.setPmStock(tSchedue.getPmThirteenth());
      return stockDto;
    } 
    if (nowDay.intValue() == 14) {
      stockDto.setAmStock(tSchedue.getAmFourteenth());
      stockDto.setPmStock(tSchedue.getPmFourteenth());
      return stockDto;
    } 
    if (nowDay.intValue() == 15) {
      stockDto.setAmStock(tSchedue.getAmFifteenth());
      stockDto.setPmStock(tSchedue.getPmFifteenth());
      return stockDto;
    } 
    if (nowDay.intValue() == 16) {
      stockDto.setAmStock(tSchedue.getAmSixteenth());
      stockDto.setPmStock(tSchedue.getPmSixteenth());
      return stockDto;
    } 
    if (nowDay.intValue() == 17) {
      stockDto.setAmStock(tSchedue.getAmSeventeenth());
      stockDto.setPmStock(tSchedue.getPmSeventeenth());
      return stockDto;
    } 
    if (nowDay.intValue() == 18) {
      stockDto.setAmStock(tSchedue.getAmEighteenth());
      stockDto.setPmStock(tSchedue.getPmEighteenth());
      return stockDto;
    } 
    if (nowDay.intValue() == 19) {
      stockDto.setAmStock(tSchedue.getAmNineteenth());
      stockDto.setPmStock(tSchedue.getPmNineteenth());
      return stockDto;
    } 
    if (nowDay.intValue() == 20) {
      stockDto.setAmStock(tSchedue.getAmTwentieth());
      stockDto.setPmStock(tSchedue.getPmTwentieth());
      return stockDto;
    } 
    if (nowDay.intValue() == 21) {
      stockDto.setAmStock(tSchedue.getAmTwentyFirst());
      stockDto.setPmStock(tSchedue.getPmTwentyFirst());
      return stockDto;
    } 
    if (nowDay.intValue() == 22) {
      stockDto.setAmStock(tSchedue.getAmTwentySecond());
      stockDto.setPmStock(tSchedue.getPmTwentySecond());
      return stockDto;
    } 
    if (nowDay.intValue() == 23) {
      stockDto.setAmStock(tSchedue.getAmTwentyThird());
      stockDto.setPmStock(tSchedue.getPmTwentyThird());
      return stockDto;
    } 
    if (nowDay.intValue() == 24) {
      stockDto.setAmStock(tSchedue.getAmTwentyFourth());
      stockDto.setPmStock(tSchedue.getPmTwentyFourth());
      return stockDto;
    } 
    if (nowDay.intValue() == 25) {
      stockDto.setAmStock(tSchedue.getAmTwentyFifth());
      stockDto.setPmStock(tSchedue.getPmTwentyFifth());
      return stockDto;
    } 
    if (nowDay.intValue() == 26) {
      stockDto.setAmStock(tSchedue.getAmTwentySixth());
      stockDto.setPmStock(tSchedue.getPmTwentySixth());
      return stockDto;
    } 
    if (nowDay.intValue() == 27) {
      stockDto.setAmStock(tSchedue.getAmTwentySeventh());
      stockDto.setPmStock(tSchedue.getPmTwentySeventh());
      return stockDto;
    } 
    if (nowDay.intValue() == 28) {
      stockDto.setAmStock(tSchedue.getAmTwentyEighth());
      stockDto.setPmStock(tSchedue.getPmTwentyEighth());
      return stockDto;
    } 
    if (nowDay.intValue() == 29) {
      stockDto.setAmStock(tSchedue.getAmTwentyNinth());
      stockDto.setPmStock(tSchedue.getPmTwentyNinth());
      return stockDto;
    } 
    if (nowDay.intValue() == 30) {
      stockDto.setAmStock(tSchedue.getAmThirtieth());
      stockDto.setPmStock(tSchedue.getPmThirtieth());
      return stockDto;
    } 
    if (nowDay.intValue() == 31) {
      stockDto.setAmStock(tSchedue.getAmThirtyFirst());
      stockDto.setPmStock(tSchedue.getPmThirtyFirst());
      return stockDto;
    } 
    return stockDto;
  }
}
